/*
 * @Author: wangqizhang
 * @Date: 2024-04-24 10:11:39
 * @LastEditors: wangqizhang
 * @LastEditTime: 2024-05-12 16:49:28
 * @FilePath: /suixinji-react/src/page/home/components/header/index.tsx
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
import React from 'react';
import { HomeOutlined, UserOutlined, BookTwoTone } from '@ant-design/icons';
import { Breadcrumb } from 'antd';
import ActionBar from '../../../../components/ActionBar';
import { connect } from 'react-redux';
import { getRouterItem, routers } from '../../../../router';
class Header extends React.Component {
  constructor(props: any) {
    super(props);
    this.state = {
      items: [
        {
          href: '/home',
          title: <HomeOutlined />,
        },
        {
          title: '工作台',
        },
      ],
    };
  }
  componentWillReceiveProps(nextProps: any) {
    const { note } = nextProps;
    this.dealData(note);
  }
  render() {
    return (
      <div className="container flex-row flex-between align-center">
        <Breadcrumb items={this.state.items}></Breadcrumb>{' '}
        <ActionBar></ActionBar>
      </div>
    );
  }
  dealData(note: any) {
    const local = window.window.location.hash
      ? window.window.location.hash.replace('#', '')
      : location.pathname;

    if (local === '/home') {
      this.setState({
        items: [
          {
            href: '/home',
            title: <HomeOutlined />,
          },
          {
            title: '工作台',
          },
        ],
      });
    } else if (local.includes('/home/note')) {
      this.setState({
        items: [
          {
            href: '/home',
            title: <HomeOutlined />,
          },
          {
            title: '工作台',
          },
          {
            title: (
              <span>
                <BookTwoTone />
                笔记:
              </span>
            ),
          },
          {
            title: note.noteInfo.note_title,
          },
        ],
      });
    } else {
      const find: any = getRouterItem(local.replace('/home/', ''));
      if (find.path) {
        this.setState({
          items: [
            {
              href: '/home',
              title: <HomeOutlined />,
            },
            {
              title: find.name || 'cuole',
            },
          ],
        });
      }
    }
  }
}
const mapStateToProps = (state: any) => ({
  note: state.note,
});
export default connect(mapStateToProps)(Header);
